﻿//////////////////////////////////////////////////////////////////////////
// FileName:fmCarDailyCheckingList.aspx
// CreateBy:DragonXiong
// CreateDate:2010-05-29
// Description:
//		  Car Daily Checking List
//      
// Modify Log:
//	
// Copyright:
/////////////////////////////////////////////////////////////////////////
using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Auto.Web.Common;
using Auto.Components;
using Model = Auto.Data.BusMan.Model;
using BLL = Auto.Data.BusMan.BLL;

namespace Auto.BusMan
{
    public partial class fmCarDailyCheckingList : System.Web.UI.Page
    {
        DataTable dt;
        BLL.BusDailyChecking bll = new BLL.BusDailyChecking();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                InitPage();
            }
        }

        private void InitPage()
        {
            this.ucDDLKeepDiv1.InitControl();
            Display();
        }

        #region --BindData--
        private void Display()
        {
            if (!string.IsNullOrEmpty(ucDDLKeepDiv1.SelectedValue))
            {
                dt = bll.GetList(" AND " + Model.BusDailyChecking.FIELD_RecDivID + " ='" + ucDDLKeepDiv1.SelectedValue + "'");
            }
            else
            {
                dt = bll.GetList("");
            }
            Session["fmCarDailyCheckingList.dt"] = dt;
            BindData();
        }

        #endregion --BindData--

        #region Event

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string startDate = txtCheckDateStart.CalendarDateText;
            string endDate = txtCheckDateEnd.CalendarDateText;
            string strWhere = string.Empty;

            if (!string.IsNullOrEmpty(ucDDLKeepDiv1.SelectedValue))
            {
                strWhere += " AND " + Model.BusDailyChecking.FIELD_RecDivID + " ='" + ucDDLKeepDiv1.SelectedValue + "'";
            }
            if (!string.IsNullOrEmpty(startDate) && !string.IsNullOrEmpty(endDate))
            {
                strWhere +=" AND "+ Model.BusDailyChecking.FIELD_CheckDate + ">='" + startDate + "'";
                strWhere += " AND " + Model.BusDailyChecking.FIELD_CheckDate + "<='" + endDate + "'";
            }
            else if (!string.IsNullOrEmpty(startDate))
            {
                strWhere +=" AND "+ Model.BusDailyChecking.FIELD_CheckDate + "='" + startDate + "'";
            }
            else if (!string.IsNullOrEmpty(endDate))
            {
                strWhere +=" AND "+ Model.BusDailyChecking.FIELD_CheckDate + "='" + endDate + "'";
            }
            dt = bll.GetList(strWhere);
            Session["fmCarDailyCheckingList.dt"] = dt;
            BindData();
        }

        #endregion Event


        #region --GridView--
        protected void BindData()
        {
            GridView1.DataSource = (DataTable)Session["fmCarDailyCheckingList.dt"];
            GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            BindData();
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {

        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string docID = (string)GridView1.DataKeys[e.RowIndex].Value;
            bll.Delete(docID);
            Display();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                //BusID
                string BusID = (string)DataBinder.Eval(e.Row.DataItem, "BusID");

                BLL.BusList bllBusList = new BLL.BusList();
                Model.BusList modelBusList = bllBusList.GetModel(BusID);
                if (modelBusList != null)
                {
                    e.Row.Cells[1].Text = modelBusList.BusIdentificationNO;
                }
                else
                {
                    e.Row.Cells[1].Text = "未知车牌";
                }


            }
        }


        #endregion --GridView--


    }
}